package com.four.dailymanage.repair.dao;

import com.four.dailymanage.repair.entity.RepairApply;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface RepairDao {
    //申请报修
    @Insert("insert into  repair_apply (dept,door,sname,content,repairDt,other,status)" +
            "values (#{dept},#{door},#{sname},#{content},#{repairDt},#{other},#{status})")
    public  int  addRepair(RepairApply repairApply);
    //分页查询
    @Select("<script>" +
            "SELECT * FROM repair_apply" +
            "  <where>" +
            "    <if test=\" sname != null\">" +
            "       sname = #{sname} " +
            "    </if>" +
            "    <if test=\" content != null\">" +
            "       and content = #{content} " +
            "    </if>" +
            "    <if test=\" repairDt != null\">" +
            "     <bind name=\"DtKey\" value=\"'%'+repairDt+'%'\"/>"+
            "       and repairDt like #{DtKey} " +
            "    </if>" +
            "    <if test=\" status != null\">" +
            "       and status = #{status} " +
            "    </if>" +
            "    <if test=\" repairMan != null\">" +
            "       and repairMan = #{repairMan} " +
            "    </if>" +
            "</where>"+
            "limit #{start},#{size}"+
            "</script>")

    public List<RepairApply> getRepairApplyByCon(int start, int size, String sname, String content,String repairDt,
                                                 String status,String repairMan);

    @Select("<script>" +
            "select count(*) from repair_apply" +
            "  <where>" +
            "    <if test=\" sname != null\">" +
            "       sname = #{sname} " +
            "    </if>" +
            "    <if test=\" content != null\">" +
            "       and content = #{content} " +
            "    </if>" +
            "    <if test=\" repairDt != null\">" +
            "     <bind name=\"DtKey\" value=\"'%'+repairDt+'%'\"/>"+
            "       and repairDt like #{DtKey} " +
            "    </if>" +
            "    <if test=\" status != null\">" +
            "       and status = #{status} " +
            "    </if>" +
            "    <if test=\" repairMan != null\">" +
            "       and repairMan = #{repairMan} " +
            "    </if>" +
            "</where>"+
            "</script>")
    public  int countRepairApply(String sname,String content,String repairDt,
                                 String status,String repairMan);

    //更新
    @Update("<script>" +
            "update  repair_apply " +
            "        <set>" +
            "            <if test=\"null!= status\">" +
            "                status =#{status}," +
            "            </if>" +
            "            <if test=\"null!= reason\">" +
            "                reason =#{reason}," +
            "            </if>" +
            "            <if test=\"null!= repairMan\">" +
            "                repairMan =#{repairMan}," +
            "            </if>" +
            "        </set>" +
            "        where id =#{id}" +
            "</script>")
    public int updateRepairApplyById(RepairApply repairApply);

    //更新
    @Update("<script>" +
            "update  repair_apply " +
            "        <set>" +
            "            <if test=\"null!= situation\">" +
            "                situation =#{situation}," +
            "            </if>" +
            "            <if test=\"null!= loppyDt\">" +
            "                loppyDt =#{loppyDt}," +
            "            </if>" +
            "        </set>" +
            "        where id =#{id}" +
            "</script>")
    public int updateRepairApply(RepairApply repairApply);
}
